import { createSlice } from "@reduxjs/toolkit";
import { Request } from "@/utils/request.js";

const initialState = {
  employee: {
    account: '',
    name: '',
    gender: '',
    phoneNumber: '',
    identificationNumber: '',
  },
};


const employeeStore = createSlice({
  name: "employee",
  initialState,
  reducers: {
    setEmployee: (state, action) => {
      state.employee = action.payload;
    },
  },
});


const addEmployee = (employee) => {

  return Request("/employeeManagement/add", employee).then((res) => {
    console.log(res);
    return res;
  });
};

const getEmployeeListWithPage = (params) => {
  return Request("/employeeManagement/getEmployeeList", params).then((res) => {
    return res;
  });
};

export const { setEmployee } = employeeStore.actions;
export { addEmployee, getEmployeeListWithPage };

export default employeeStore.reducer;
